import request from "@/utils/request.ts";
import type {SysResponse} from "@/api/commonType.ts";
import type {phoneLoginForm, pwLoginForm, SysAuthToken} from "@/api/login/types.ts";


enum API {
  SEND_V_CODE ='/api/auth/login/sendVCode',
  PHONE_LOGIN = '/api/auth/login/phone',
  PW_LOGIN = '/api/auth/login/pw',

  LOGOUT = '/api/auth/logout',
}


//发送验证码
export function sendCode(phone: string) {
  return request.get<string, SysResponse<null>>(API.SEND_V_CODE, {
    params: {
      phone
    }
  })
}

//手机号登录
export function phoneLogin(data: phoneLoginForm) {
  return request.post<string, SysResponse<SysAuthToken>>(API.PHONE_LOGIN, data)
}

//密码登录
export function pwLogin(data: pwLoginForm) {
  return request.post<string, SysResponse<SysAuthToken>>(API.PW_LOGIN, data)
}


//退出登录
export function logout() {
  return request.delete<null, SysResponse<null>>(API.LOGOUT)
}

